library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.4 v dplyr 1.0.7
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 2.0.1 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(p8105.datasets)
library(plotly)
##
## 载入程辑包:'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
This plot aims to show the total number of ordered items in each aisle.
data(instacart)
instacart_aisle =
instacart %>%
group_by(aisle) %>%
summarize(total = n()) %>%
arrange(desc(total)) %>%
filter(total > 10000) %>%
mutate(aisle = fct_reorder(aisle, total)) %>%
plot_ly(x = ~aisle, y = ~total, colors = ~aisle, type = "bar", alpha = 0.5)
ggplotly(instacart_aisle)
This plot aims to show the boxplots of the order hour of day of Pink Lady Apples and Coffee Ice Cream respectively.
instacart_hour =
instacart %>%
filter(product_name %in% c("Pink Lady Apples", "Coffee Ice Cream")) %>%
group_by(product_name, order_dow) %>%
plot_ly(y = ~order_hour_of_day, color = ~product_name, type = "box", colors = "viridis")
ggplotly(instacart_hour)
This histogram aims to show the relationship between order hour and the day of Pink Lady Apples and Coffee Ice Cream respectively.
instacart_day =
instacart %>%
filter(product_name %in% c("Pink Lady Apples", "Coffee Ice Cream")) %>%
group_by(product_name, order_dow) %>%
plot_ly(x = ~order_hour_of_day, y = ~order_dow, color = ~product_name, type = "histogram")
ggplotly(instacart_day)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels